package team.kirohuji.repository.jpa.user;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import team.kirohuji.domain.user.Priority;

/**
 * 这个类用来对权限和菜单映射的管理
 * 
 * @author kirohuji
 * 
 */
@Repository
public interface PriorityRepository extends JpaRepository<Priority, Integer> {
	
	/**
	 * 根据父菜单，查询子菜单
	 * @param parentId 父菜单ID
	 * @param priorityType 权限类型：0-系统后台用户权限，1-微信端用户权限
	 * @param menuIdList  用户菜单ID
	 * @return Priority列表
	 */
	@Query(value="select * from priority where parent_id=?1 and priority_type=?2 order by priority_id asc", nativeQuery = true)
	List<Priority> queryListParentId( Integer parentId,Integer priorityType);
	
	/**
	 * 后台 获取 非按钮的 权限菜单集合
	 * 获取不包含按钮的菜单列表
	 * @return Priority列表
	 */
	@Query(value="select * from priority where node_type!=2 order by priority_id asc", nativeQuery = true)
	List<Priority> queryNotButtonList();

	@Query(value="select * from priority where priority_type=?1 order by priority_id asc", nativeQuery = true)
	List<Priority> queryPriorityByPriorityType(String priorityType);
	
	/**
	 * 列出所有父权限
	 * 
	 * @return Priority列表
	 */
	@Query(value="SELECT * FROM priority WHERE parent_id = 0", nativeQuery = true)
	List<Priority> queryParentPriority();
}